package com.sqlcheck.service;

import com.sqlcheck.model.SqlStatement;
import lombok.Builder;
import lombok.Data;

import java.util.List;
import java.util.Map;

/**
 * SQL提取结果
 */
@Data
@Builder
public class SqlExtractionResult {

    private boolean success;
    private String errorMessage;
    private List<SqlStatement> sqlStatements;
    private ExtractionMetadata metadata;

    public static SqlExtractionResult success(List<SqlStatement> sqlStatements, ExtractionMetadata metadata) {
        return SqlExtractionResult.builder()
                .success(true)
                .sqlStatements(sqlStatements)
                .metadata(metadata)
                .build();
    }

    public static SqlExtractionResult failure(String errorMessage) {
        return SqlExtractionResult.builder()
                .success(false)
                .errorMessage(errorMessage)
                .build();
    }

    /**
     * SQL提取元数据
     */
    @Data
    @Builder
    public static class ExtractionMetadata {
        private String extractionType;          // 提取类型：GIT_SCAN, DATABASE_DDL_SCAN
        private String sourceLocation;          // 源位置：Git仓库URL或数据库连接信息
        private int totalStatements;            // 总语句数
        private Map<String, Integer> sourceTypeCounts; // 按来源类型统计的语句数量
        private long extractionTimeMs;          // 提取耗时（毫秒）
        private Map<String, Object> additionalInfo; // 额外信息
    }
}